// 验证近战系统修复
// 在浏览器控制台中运行此脚本来验证近战系统

console.log('🔧 开始验证近战系统修复...');

// 1. 验证核心类是否存在
function validateClasses() {
    console.log('📋 验证核心类...');
    
    const requiredClasses = ['Player', 'MeleeWeapon', 'Weapon', 'Zombie'];
    const results = [];
    
    requiredClasses.forEach(className => {
        if (typeof window[className] !== 'undefined') {
            results.push(`✅ ${className} 类存在`);
        } else {
            results.push(`❌ ${className} 类不存在`);
        }
    });
    
    return results;
}

// 2. 验证近战武器创建
function validateMeleeWeaponCreation() {
    console.log('⚔️ 验证近战武器创建...');
    
    const weaponTypes = ['knife', 'bat', 'sword', 'axe'];
    const results = [];
    
    weaponTypes.forEach(type => {
        try {
            const weapon = new MeleeWeapon(type);
            if (weapon.stats && weapon.stats.name) {
                results.push(`✅ ${type}: ${weapon.stats.name} (伤害: ${weapon.stats.damage}, 范围: ${weapon.stats.range})`);
            } else {
                results.push(`❌ ${type}: 武器数据不完整`);
            }
        } catch (error) {
            results.push(`❌ ${type}: 创建失败 - ${error.message}`);
        }
    });
    
    return results;
}

// 3. 验证玩家近战系统
function validatePlayerMeleeSystem() {
    console.log('🎮 验证玩家近战系统...');
    
    const results = [];
    
    try {
        const player = new Player(400, 300);
        
        // 检查近战武器属性
        if (player.meleeWeapon) {
            results.push(`✅ 玩家初始近战武器: ${player.meleeWeapon.stats.name}`);
        } else {
            results.push(`❌ 玩家缺少初始近战武器`);
        }
        
        // 检查战斗模式
        if (player.combatMode) {
            results.push(`✅ 玩家战斗模式: ${player.combatMode}`);
        } else {
            results.push(`❌ 玩家缺少战斗模式`);
        }
        
        // 检查模式切换
        const initialMode = player.combatMode;
        player.switchCombatMode();
        if (player.combatMode !== initialMode) {
            results.push(`✅ 模式切换成功: ${initialMode} → ${player.combatMode}`);
        } else {
            results.push(`❌ 模式切换失败`);
        }
        
        // 检查近战攻击方法
        if (typeof player.performMeleeAttack === 'function') {
            results.push(`✅ 近战攻击方法存在`);
        } else {
            results.push(`❌ 近战攻击方法不存在`);
        }
        
        // 检查近战攻击处理方法
        if (typeof player.processMeleeAttack === 'function') {
            results.push(`✅ 近战攻击处理方法存在`);
        } else {
            results.push(`❌ 近战攻击处理方法不存在`);
        }
        
    } catch (error) {
        results.push(`❌ 玩家系统验证失败: ${error.message}`);
    }
    
    return results;
}

// 4. 验证僵尸系统
function validateZombieSystem() {
    console.log('🧟 验证僵尸系统...');
    
    const results = [];
    
    try {
        const zombie = new Zombie(100, 100, 'normal');
        
        // 检查基本属性
        if (zombie.health > 0) {
            results.push(`✅ 僵尸血量: ${zombie.health}`);
        } else {
            results.push(`❌ 僵尸血量无效`);
        }
        
        // 检查takeDamage方法
        if (typeof zombie.takeDamage === 'function') {
            results.push(`✅ takeDamage方法存在`);
        } else {
            results.push(`❌ takeDamage方法不存在`);
        }
        
        // 模拟伤害测试
        const initialHealth = zombie.health;
        zombie.health -= 10; // 直接减少血量模拟近战攻击
        
        if (zombie.health === initialHealth - 10) {
            results.push(`✅ 血量减少正常: ${initialHealth} → ${zombie.health}`);
        } else {
            results.push(`❌ 血量减少异常`);
        }
        
    } catch (error) {
        results.push(`❌ 僵尸系统验证失败: ${error.message}`);
    }
    
    return results;
}

// 5. 验证武器范围平衡
function validateWeaponRanges() {
    console.log('📏 验证武器范围平衡...');
    
    const results = [];
    const weaponTypes = ['knife', 'bat', 'sword', 'axe'];
    
    weaponTypes.forEach(type => {
        try {
            const weapon = new MeleeWeapon(type);
            results.push(`✅ ${weapon.stats.name}: 范围${weapon.stats.range}, 伤害${weapon.stats.damage}`);
        } catch (error) {
            results.push(`❌ ${type}: 验证失败`);
        }
    });
    
    return results;
}

// 执行所有验证
function runAllValidations() {
    console.log('🚀 开始完整验证...\n');
    
    const allResults = [
        ...validateClasses(),
        ...validateMeleeWeaponCreation(),
        ...validatePlayerMeleeSystem(),
        ...validateZombieSystem(),
        ...validateWeaponRanges()
    ];
    
    console.log('\n📊 验证结果汇总:');
    allResults.forEach(result => console.log(result));
    
    const successCount = allResults.filter(r => r.includes('✅')).length;
    const totalCount = allResults.length;
    
    console.log(`\n🎯 成功率: ${successCount}/${totalCount} (${(successCount/totalCount*100).toFixed(1)}%)`);
    
    if (successCount === totalCount) {
        console.log('🎉 所有验证通过！近战系统修复成功！');
    } else {
        console.log('⚠️ 部分验证失败，请检查具体问题');
    }
}

// 导出验证函数
if (typeof module !== 'undefined' && module.exports) {
    module.exports = {
        validateClasses,
        validateMeleeWeaponCreation,
        validatePlayerMeleeSystem,
        validateZombieSystem,
        validateWeaponRanges,
        runAllValidations
    };
}

console.log('📝 验证脚本已加载。在浏览器控制台中运行 runAllValidations() 来执行完整验证。');